<? 
    session_start();
	include ("core/conn.php");
	$db = get_conn();
	check_session();

	$id = $_GET['id'];
	$id_location = $_GET['id_location'];
	
	if($id != ''){
		$sql = " select * from visitors where id_visitor=".$_GET['id']; 
		$result = mysql_query($sql);	
		if($result){
			$row = mysql_fetch_array($result);

			$id_visitor = $row['id_visitor'];
			$id_number = $row['id_number'];
			$vtype = $row['vtype'];
			$name = $row['name'];
			$car_id = $row['car_id'];
			$access_restrictions = $row['access_restrictions'];
			$reponse = $row['reponse'];			
			
		}else{
			error_handling(__FUNCTION__.$sql,mysql_error());
		}
	}
	
?>
<html>
<head>
<script>
<!--

	function ver_password(){
		if(document.getElementById('passwd').type == 'text'){
			document.getElementById('passwd').type = 'password'
		}else{
			document.getElementById('passwd').type = 'text'	
		}
	}
	
	function checkdata(obj){
								
					
			if(obj.id_number.value ==''){
									
				alert('Debe indicar la cedula');
									
				obj.id_number.focus();
									
				return false;
								
			}
								
			if(obj.vtype.value ==''){
									
				alert('Debe seleccionar el tipo');
									
				obj.vtype.focus();
									
				return false;
								
			}
								
			if(obj.name.value ==''){
									
				alert('Debe indicar el nombre');
									
				obj.name.focus();
									
				return false;
								
			}
								
	
								
			if(obj.reponse.value ==''){
									
				alert('Debe seleccionar una respuesta');
									
				obj.reponse.focus();
									
				return false;
								
			}
		return true;
							
		}			
-->
</script>
<link href="css/admin_styles.css" rel="stylesheet" type="text/css" />
<script src="tools/jq_dp/js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="tools/jq_dp/js/jquery-ui-1.8.11.custom.min.js" type="text/javascript"></script>

<script type="text/javascript" lang="javascript" src="tools/modal/jquery-1.3.2.min.js"></script>
<script src="js/jquery.maskedinput-1.2.2.js"></script>
    <script>
	$(document).ready(function(){
		if($("#phone1")) $("#phone1").mask("****-****");
		if($("#phone2")) $("#phone2").mask("****-****");		
		if($("#phone3")) $("#phone3").mask("****-****");		

		$( "#moving_date" ).datepicker();

		
	}); 
	
	
		
	</script>

</head>
<body>
<form name='users' method='post' action='core/visitors.php' onsubmit='return checkdata(this)'>
  <table border='0' width="100%" align="center">
    <tr>
      <td ><div align="center">
        <h2>Visitantes</h2>
      </div></td>
    </tr>
    <tr>
      <td class="table_border"><table width='100%' border='0'  >
        <tr>
          <td class="texto">Filial:</td>
          <td><? 
		  
		  if($_SESSION['session_id_location'] !=''){
				$sql = "select l.id_location as myvalue, concat(l.number,' | ',l.acc_id) as mydesc  from `locations` l where l.id_location = ".$_SESSION['session_id_location']." order by l.id_location";
		  }else{
				$sql = "select l.id_location as myvalue, concat(l.number,' | ',l.acc_id) as mydesc  from `locations` l order by l.id_location";
		  }
		$js =" tabindex='1' ";
		echo dbcombosql($sql,'id_location',$id_location,$js,$extraitems); ?></td>
          <td nowrap class="texto">Tipo de visitante:</td>
          <td colspan="3"><select name="vtype" id="vtype">
            <option value="215"><?php echo get_texto(215);?></option>
            <option value="216"><?php echo get_texto(216);?></option>
            <option value="217"><?php echo get_texto(217);?></option>
            <option value="218"><?php echo get_texto(218);?></option>
          </select></td>
        </tr>
        <tr>
          <td width="9%" class="texto"><div align="left">Nombre:</div></td>
          <td width="30%"><input  tabindex="1"  name='name' type='text'  id="name" value="<? echo $name;?>" size="40" />
            <input type='hidden' name='id_visitor' value='<? echo $id_visitor;?>' /></td>
          <td width="6%"><span class="texto">Cedula:</span></td>
          <td width="13%"><input tabindex="4" name='id_number' type='text'  id="id_number" value='<? echo $id_number;?>' size="10" /></td>
          <td width="9%" nowrap><span class="texto">Vehiculo Placa:</span></td>
          <td width="33%"><input tabindex="4" name='car_id' type='text'  id="car_id" value='<? echo $car_id;?>' size="10" /></td>
        </tr>

        <tr>
          <td nowrap class="texto">Accion a realizar:</td>
          <td colspan="5">
          <select name="reponse" id="reponse">
            <option value="214" <? echo getStatus($reponse,214)?>><?php echo get_texto(214);?></option>
            <option value="210" <? echo getStatus($reponse,210)?>><?php echo get_texto(210);?></option>
            <option value="211" <? echo getStatus($reponse,211)?>><?php echo get_texto(211);?></option>
            <option value="212" <? echo getStatus($reponse,212)?>><?php echo get_texto(212);?></option>
            <option value="213" <? echo getStatus($reponse,213)?>><?php echo get_texto(213);?></option>
          </select></td>
        </tr>
        <tr>
          <td class="texto">Comentarios:</td>
          <td colspan="5"><textarea name="access_restrictions" cols="80" rows="3" id="access_restrictions" ><? echo $access_restrictions;?></textarea></td>
        </tr>
        <tr>
          <td colspan="6" class="texto"><hr size="1"></td>
        </tr>
        <tr>
          <td colspan='6' align='center'><?
					  if ($id != ""){
						echo "<input type='submit' name='Actualizar' value='Actualizar'>";
						echo "&nbsp;<input type='submit' name='Eliminar' value='Eliminar'>";										
						echo "&nbsp;<input type='submit' name='Nuevo' value='Cancelar'>";
					  }else{
						echo "<input type='submit' name='Agregar' value='Guardar'>";
						echo "&nbsp;<input type='submit' name='Nuevo' value='Cancelar'>";
					  }
					?></td>
        </tr>
      </table></td>
    </tr>
  </table>
</form>
</body>
</html>

<?php
function get_residents_options($id_resident){
	if($id_resident !=''){
		$sql ="select id_option from resident_options_granted where id_resident=".$id_resident;
		$result = mysql_query($sql);
		if($result){
			while($row = mysql_fetch_array($result)){
				$options.=$row['id_option'].",";
			}
			$options = substr($options,0,(strlen($options)-1));
		}else{
			
			error_handling("get_user_options a: ".$sql,mysql_error());
		}
	}
	

	$cols =4;
	$sql ="select * from resident_options ";
	$result = mysql_query($sql);
	if($result){
		while($row = mysql_fetch_array($result)){
			if($counter ==0){
				$data.="<tr>";
			}
			$data.="<td><input type='checkbox' name='id_option[]' value='".$row['id_option']."' id='r_".$row['id_option']."' ".is_in_list($options,$row['id_option'])."><label  class='texto' for='r_".$row['id_option']."'>".$row['name']."</label></td>";
			$counter++;
			if($counter ==$cols){
				$data.="</tr>";
				$counter =0;
			}
		}//while
		return "<table border='0' >".$data."</table>";
	}else{
		error_handling("get_roles: ".$sql,mysql_error());
	}
}

?>